<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Spring Boot Profiles 环境隔离指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            transition: all 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            padding: 20px;
            overflow-x: auto;
            position: relative;
            margin: 20px 0;
        }
        
        .code-block::before {
            content: attr(data-lang);
            position: absolute;
            top: 8px;
            right: 12px;
            font-size: 12px;
            color: #858585;
            text-transform: uppercase;
        }
        
        .feature-card {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            padding: 30px;
            border-radius: 16px;
            transition: all 0.3s ease;
        }
        
        .feature-card:hover {
            transform: scale(1.02);
            box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2);
        }
        
        .timeline-item {
            position: relative;
            padding-left: 40px;
            margin-bottom: 30px;
        }
        
        .timeline-item::before {
            content: '';
            position: absolute;
            left: 10px;
            top: 8px;
            width: 12px;
            height: 12px;
            background: #667eea;
            border-radius: 50%;
            box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.2);
        }
        
        .timeline-item::after {
            content: '';
            position: absolute;
            left: 15px;
            top: 20px;
            width: 2px;
            height: calc(100% + 10px);
            background: #e0e0e0;
        }
        
        .timeline-item:last-child::after {
            display: none;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
            padding: 20px;
            border-radius: 12px;
            margin: 20px 0;
            position: relative;
            overflow: hidden;
        }
        
        .highlight-box::before {
            content: '\f0eb';
            font-family: 'Font Awesome 6 Free';
            font-weight: 900;
            position: absolute;
            right: 20px;
            top: 50%;
            transform: translateY(-50%);
            font-size: 48px;
            opacity: 0.1;
        }
        
        .mermaid {
            margin: 30px 0;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fade-in {
            animation: fadeInUp 0.6s ease-out;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-8">
        <div class="max-w-6xl mx-auto">
            <h1 class="text-5xl font-bold mb-6 animate-fade-in">
                <i class="fas fa-layer-group mr-4"></i>
                Spring Boot Profiles 环境隔离指南
            </h1>
            <p class="text-xl leading-relaxed opacity-90 animate-fade-in" style="animation-delay: 0.2s;">
                掌握 Spring Boot 中的 Profiles 特性，实现优雅的多环境配置管理，让你的应用在开发、测试和生产环境中游刃有余。
            </p>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-6xl mx-auto px-8 py-12">
        
        <!-- Introduction Card -->
        <div class="content-card rounded-2xl shadow-xl p-8 mb-8 animate-fade-in" style="animation-delay: 0.3s;">
            <div class="text-lg leading-relaxed text-gray-700">
                <p class="mb-4 text-indent-8">
                    在现代软件开发中，环境隔离是确保应用程序在不同环境中以一致且可靠的方式运行的关键。无论是开发、测试还是生产环境，每个环境都可能具有不同的配置需求，比如数据库连接、服务端口、API密钥等。为了有效地管理这些差异，Spring Boot提供了一种非常强大的特性——Profiles。
                </p>
                <p class="text-indent-8">
                    Spring Profiles允许我们根据特定的环境来选择性地加载配置，这样我们就可以为每个环境定义独立的配置文件，从而避免手动修改配置的繁琐和错误。使用Profiles，我们可以将应用程序的配置与运行时环境解耦，提升开发效率并降低出错率。
                </p>
            </div>
        </div>

        <!-- What is Spring Profiles -->
        <div class="content-card rounded-2xl shadow-xl p-8 mb-8 animate-fade-in" style="animation-delay: 0.4s;">
            <h2 class="section-title text-3xl font-bold mb-6 text-gray-800">
                什么是Spring Profiles
            </h2>
            
            <div class="grid md:grid-cols-2 gap-6 mb-8">
                <div class="feature-card">
                    <h3 class="text-2xl font-bold mb-4">
                        <i class="fas fa-cogs mr-2"></i>基本概念
                    </h3>
                    <p class="leading-relaxed">
                        Profile 是一种标记，表示应用程序在某个特定环境下的运行状态。Spring Profiles 允许我们根据特定的标识符来激活和配置不同的 Beans 和属性。
                    </p>
                </div>
                
                <div class="feature-card" style="background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);">
                    <h3 class="text-2xl font-bold mb-4">
                        <i class="fas fa-shield-alt mr-2"></i>环境隔离
                    </h3>
                    <p class="leading-relaxed">
                        使用 Profiles，开发者可以将环境相关的配置逻辑从代码中分离出来，使应用程序能够在不同环境中使用各自特定的设置。
                    </p>
                </div>
            </div>

            <div class="bg-gray-50 rounded-xl p-6">
                <h3 class="text-xl font-semibold mb-4 text-gray-800">
                    <i class="fas fa-list-check mr-2 text-purple-600"></i>使用场景
                </h3>
                <div class="space-y-3">
                    <div class="flex items-start">
                        <i class="fas fa-database mt-1 mr-3 text-blue-500"></i>
                        <div>
                            <strong>数据库配置：</strong>在开发环境中使用一个测试数据库，而在生产环境中使用一个正式数据库。
                        </div>
                    </div>
                    <div class="flex items-start">
                        <i class="fas fa-cloud mt-1 mr-3 text-green-500"></i>
                        <div>
                            <strong>第三方服务的配置：</strong>在开发环境中使用 Mock 服务，在生产环境中使用真实的服务。
                        </div>
                    </div>
                    <div class="flex items-start">
                        <i class="fas fa-file-alt mt-1 mr-3 text-orange-500"></i>
                        <div>
                            <strong>日志级别：</strong>在开发环境中可以设置更详细的日志级别，而在生产环境中则可以设置为较低的日志级别。
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Configuration Files Organization -->
        <div class="content-card rounded-2xl shadow-xl p-8 mb-8 animate-fade-in" style="animation-delay: 0.5s;">
            <h2 class="section-title text-3xl font-bold mb-6 text-gray-800">
                配置文件的组织
            </h2>
            
            <div class="highlight-box mb-6">
                <h3 class="text-xl font-semibold mb-3">
                    <i class="fas fa-folder-tree mr-2"></i>配置文件结构
                </h3>
                <div class="code-block" data-lang="text">
                    <pre>my-spring-boot-app/
├── src/
│   └── main/
│       └── resources/
│           ├── application.yml          # 默认配置
│           ├── application-dev.yml      # 开发环境
│           ├── application-test.yml     # 测试环境
│           └── application-prod.yml     # 生产环境</pre>
                </div>
            </div>

            <div class="grid md:grid-cols-2 gap-6">
                <div class="bg-blue-50 rounded-xl p-6">
                    <h4 class="text-lg font-semibold mb-3 text-blue-800">
                        <i class="fas fa-file-code mr-2"></i>Properties 格式
                    </h4>
                    <div class="code-block" data-lang="properties">
                        <pre>spring.datasource.url=jdbc:mysql://localhost:3306/mydb
spring.datasource.username=root
spring.datasource.password=secret</pre>
                    </div>
                </div>
                
                <div class="bg-green-50 rounded-xl p-6">
                    <h4 class="text-lg font-semibold mb-3 text-green-800">
                        <i class="fas fa-file-alt mr-2"></i>YAML 格式
                    </h4>
                    <div class="code-block" data-lang="yaml">
                        <pre>spring:
  datasource:
    url: jdbc:mysql://localhost:3306/mydb
    username: root
    password: secret</pre>
                    </div>
                </div>
            </div>
        </div>

        <!-- Profile Activation -->
        <div class="content-card rounded-2xl shadow-xl p-8 mb-8 animate-fade-in" style="animation-delay: 0.6s;">
            <h2 class="section-title text-3xl font-bold mb-6 text-gray-800">
                Profile的激活方式
            </h2>
            
            <div class="space-y-6">
                <div class="timeline-item">
                    <h3 class="text-xl font-semibold mb-2">通过配置文件激活</h3>
                    <div class="code-block" data-lang="properties">
                        <pre>spring.profiles.active=dev</pre>
                    </div>
                </div>
                
                <div class="timeline-item">
                    <h3 class="text-xl font-semibold mb-2">通过命令行参数激活</h3>
                    <div class="code-block" data-lang="bash">
                        <pre>java -jar myapp.jar --spring.profiles.active=prod</pre>
                    </div>
                </div>
                
                <div class="timeline-item">
                    <h3 class="text-xl font-semibold mb-2">通过环境变量激活</h3>
                    <div class="code-block" data-lang="bash">
                        <pre>export SPRING_PROFILES_ACTIVE=prod</pre>
                    </div>
                </div>
                
                <div class="timeline-item">
                    <h3 class="text-xl font-semibold mb-2">通过代码激活（测试环境）</h3>
                    <div class="code-block" data-lang="java">
                        <pre>@ActiveProfiles("test")
public class MyServiceTest {
    // Test methods
}</pre>
                    </div>
                </div>
            </div>
        </div>

        <!-- Conditional Configuration -->
        <div class="content-card rounded-2xl shadow-xl p-8 mb-8 animate-fade-in" style="animation-delay: 0.7s;">
            <h2 class="